import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { Tabs, Modal, Popover, Badge, Toast } from 'antd-mobile'
import Slider from 'react-slick'
// import Scrolllock from 'react-scrolllock'
import { Button, Image, Icon, Item, NavBar, InputNumber, Gird, FlatList } from 'components'
import './shopDetail.less'
import { post } from '../../utils'
import { isArray, assign } from 'muka'
import { Link } from 'react-router-dom'

export default class ShopDetail extends React.Component<any, any> {

    public state: any = {
        info: {},
        index: 1,
        imgItemLength: 0,
        selectAddressObj: {},
        goodsRecommends: [],
        data: {
            scrollImg: ['../../assets/phone1.png', '../../assets/phone1.png', '../../assets/phone1.png']
        },
        shareVisible: false,
        moreVisible: false,
        selectSpecifications: false,
        selectOptions: false,
        addressVisible: false,
        buyGoodsNum: 1,
        spec: [],
        topBarClass: 'ShopDetail_topBar',
        tabPage: 0,
        refreshing: false,
        selectAddress: [],
        selectAddressVal: '',
        shareItem: [
            {
                icon: 'weChat',
                text: '微信好友',
                color: '#51b341'
            },
            {
                icon: 'weChat',
                text: '朋友圈',
                color: '#9ad122'
            },
            {
                icon: 'weChat',
                text: 'QQ好友',
                color: '#45b1f3'
            },
            {
                icon: 'weChat',
                text: 'QQ空间',
                color: '#ffc000'
            },
            {
                icon: 'weChat',
                text: '新浪微博',
                color: '#f35b78'
            },
            {
                icon: 'weChat',
                text: '复制链接',
                color: '#00a0e9'
            }
        ]
    }
    private tabs = [
        { title: '商品' },
        { title: '详情' },
        { title: '推荐' }
    ]

    private lijigoumai: boolean = true
    private jiarugouwuche: boolean = true

    private flatNode: any

    // private ptr: any

    public render() {
        const { index, moreVisible, addressVisible, selectSpecifications, topBarClass, tabPage, buyGoodsNum, selectAddressVal, shareItem, selectOptions, goodsRecommends } = this.state
        const { addressData, info, spec } = this.props
        const settings = {
            dots: false,
            infinite: false,
            focusOnSelect: true,
            speed: 500,
            arrows: false,
            slidesToShow: 1,
            slidesToScroll: 1,
            beforeChange: (oldIndex: number, newIndex: number) => {
                this.setState({
                    index: newIndex + 1
                })
            }
        }
        return (
            <div className="ShopDetail">
                {/* {(selectSpecifications || addressVisible) && <Scrolllock />} */}
                <div className="ShopDetail_topBar_placeHolder">
                    <div className={topBarClass}>
                        <NavBar className="ShopDetail_NavBar" title={<div className="ShopDetail_topBar_center"><div className="ShopDetail_topBar_tab"><Tabs page={tabPage} tabBarActiveTextColor="#fa0000" animated={false} tabs={this.tabs} onTabClick={this.handleClickTabs} /></div></div>} />
                    </div>
                </div>
                <div className="ShopDetail_scorll">
                    <div className="carousel_header">
                        <div className="carousel_header_back">
                            {/* <Button className="carousel_header_btn" type="circle">
                                <Icon type="arrow_left" />
                            </Button> */}
                        </div>
                        <div className="carousel_header_shareMore">
                            <Button className="carousel_header_btn carousel_header_shareBtn" type="circle" onClick={this.showModal('shareVisible')}>
                                <Icon type="share" />
                            </Button>
                            <Popover
                                mask={true}
                                visible={moreVisible}
                                overlay={[
                                    (<div className="carousel_header_popover_item">
                                        <div className="carousel_header_popover_itemIconWrap">
                                            <Icon type="message" className="carousel_header_popover_itemIcon">
                                                <Badge text="99" size="small" className="DINPro carousel_header_popover_itemBadge" />
                                            </Icon>
                                        </div>
                                        <div className="carousel_header_popover_itemContent">消息</div>
                                    </div>),
                                    (<div className="carousel_header_popover_item">
                                        <div className="carousel_header_popover_itemIconWrap">
                                            <Icon type="homepage" className="carousel_header_popover_itemIcon" />
                                        </div>
                                        <div className="carousel_header_popover_itemContent">首页</div>
                                    </div>),
                                    (<div className="carousel_header_popover_item">
                                        <div className="carousel_header_popover_itemIconWrap">
                                            <Icon type="search" className="carousel_header_popover_itemIcon" />
                                        </div>
                                        <div className="carousel_header_popover_itemContent">搜索</div>
                                    </div>),
                                    (<div className="carousel_header_popover_item">
                                        <div className="carousel_header_popover_itemIconWrap">
                                            <Icon type="follow" className="carousel_header_popover_itemIcon" />
                                        </div>
                                        <div className="carousel_header_popover_itemContent">我的关注</div>
                                    </div>),
                                    (<div className="carousel_header_popover_item">
                                        <div className="carousel_header_popover_itemIconWrap">
                                            <Icon type="foot" className="carousel_header_popover_itemIcon" />
                                        </div>
                                        <div className="carousel_header_popover_itemContent">浏览记录</div>
                                    </div>),
                                ]}
                                onVisibleChange={this.handleMoreVisibleChange}
                                onSelect={this.onSelect}
                            >
                                <Button className="carousel_header_btn " type="circle" >
                                    <Icon type="more" />
                                </Button>
                            </Popover>
                        </div>
                    </div>
                    <Slider {...settings}>
                        {
                            isArray(info.images) && info.images.map((item: any, i: number) => {
                                return (
                                    <div className="carousel_item" key={i}><img className="carousel_itemImg" src={item} /></div>
                                )
                            })
                        }
                    </Slider>
                    <div className="carousel_footer">
                        <div><span>{index}</span>/<span>{info.images && info.images.length}</span></div>
                    </div>
                </div>
                <div className="ShopDetail_goodsInfo">
                    {/* <div className="ShopDetail_goodsInfo_item ShopDetail_goodsInfo_price">
                        <div><span>￥</span><span className="DINPro">0+8206</span><span>恒豆</span></div>
                        <div>
                            <div className="ShopDetail_goodsInfo_price_right">
                                <span><Image className="ShopDetail_country" src={require('../../assets/shopDetail_country.png')} /></span>
                                <span>中国</span>
                            </div>
                            <div className="ShopDetail_goodsInfo_price_right">
                                <span className="ShopDetail_goodsInfo_followIcon"><Icon type="follow" /></span>
                                <span>关注</span>
                            </div>
                        </div>
                    </div> */}

                    <div className=" ShopDetail_goodsInfo_item ShopDetail_goodsInfo_Wrap">
                        <div className="ShopDetail_goodsInfo_titleWrap">
                            <div className="ShopDetail_goodsInfo_title">{info.name}</div>
                            {info.is_goods_collect === 0 ? <div className="ShopDetail_goodsInfo_follow" onClick={this.handleSeller.bind(this, 1)}>
                                <div><Icon type="follow" className="ShopDetail_goodsInfo_follow_icon" /></div>
                                <div>关注</div>
                            </div> : <div className="ShopDetail_goodsInfo_follow" onClick={this.handleSeller.bind(this, 2)}>
                                    <div><Icon type="live" className="ShopDetail_goodsInfo_follow_icon" style={{ color: '#fa0000' }} /></div>
                                    <div>取消</div>
                                </div>}
                        </div>
                        <div className="ShopDetail_goodsInfo_price">
                            <span>价格:</span>
                            <span>￥</span>
                            <span className="DINPro">{info.price}+{info.price_q}</span>
                            <span>&nbsp;恒豆</span>
                        </div>
                        <div className="ShopDetail_goodsInfo_buyInfo">
                            <div>
                                恒豆:<span><img src={require('../../assets/hd_img.png')} /></span>
                                <span> {info.price_all}</span>
                            </div>
                            <div>
                                <img src={require('../../assets/shopDetail_country.png')} />
                                <span className="ShopDetail_goodsInfo_buyInfo_country">{info.country}</span>
                                <span>已有{info.sale_number}人购买</span>
                            </div>
                        </div>
                    </div>
                    <div className="ShopDetail_goodsInfo_guarantee ShopDetail_goodsInfo_item">
                        <div><img src={require('../../assets/ShopDetail_guarantee_icon.png')} /><span>中恒品质保障</span></div>
                        <div><img src={require('../../assets/ShopDetail_guarantee_icon.png')} /><span>48小时极速免运费</span></div>
                        <div><img src={require('../../assets/ShopDetail_guarantee_icon.png')} /><span>无忧售后服务</span></div>
                    </div>
                    <div className="ShopDetail_goodsInfo_item ShopDetail_goodsInfo_specifications" onClick={this.showModal('selectSpecifications')} >
                        <Item className="" title={<div className="ShopDetail_goodsInfo_itemTitle"><span>选择</span><span>{info.spec || '请选择规格'}</span></div>} value={<Icon type="more" />} />
                    </div>
                    <div className="ShopDetail_goodsInfo_item ShopDetail_goodsInfo_specifications" onClick={this.showModal('selectOptions')} >
                        <Item className="" title={<div className="ShopDetail_goodsInfo_itemTitle"><span>参数</span></div>} value={<Icon type="more" />} />
                    </div>
                    {selectAddressVal && <div className="ShopDetail_goodsInfo_address ShopDetail_goodsInfo_item" onClick={this.showModal('addressVisible')}>
                        <Item className="" title={<div className="ShopDetail_goodsInfo_itemTitle"><span>送至</span><span>{selectAddressVal && <Icon type="address" className="ShopDetail_goodsInfo_itemTitle_address" />}{selectAddressVal}</span></div>} value={<Icon type="more" />} />
                    </div>}
                    <div className="ShopDetail_goodsInfo_freight ShopDetail_goodsInfo_item">
                        <Item className="" title={<div className="ShopDetail_goodsInfo_itemTitle"><span>运费</span><span>快递{info.freight || 0}元</span></div>} />
                    </div>
                    <div className="ShopDetail_Tabs">
                        <Tabs
                            tabs={[
                                { title: <div className="ShopDetail_Tabs_title_item">商品介绍<span /></div> }
                            ]}
                            animated={false}
                            swipeable={false}
                            tabBarActiveTextColor="#fa0000"
                        >
                            <div className="ShopDetail_Tabs_item" dangerouslySetInnerHTML={{ __html: info.content }} />
                        </Tabs>
                        <FlatList
                            data={goodsRecommends}
                            style={{
                                paddingBottom: '2.5rem'
                            }}
                            ref={(e: any) => { this.flatNode = e }}
                            renderItem={(item: any, i: number) => {
                                return (
                                    <Link key={i} to={`/shopDetail/${item.id}`}>
                                        <div className="live_item">
                                            <div className="live_item_img">
                                                <Image src={item.pic} />
                                            </div>
                                            <div className="live_item_content">
                                                <div className="live_item_content_title">{item.name}</div>
                                                <div className="live_item_content_label">
                                                    ¥ {item.price}+{item.price_q}
                                                    <span>恒豆</span>
                                                </div>
                                            </div>
                                        </div>
                                    </Link>
                                )
                            }}
                        />
                    </div>
                    <div className="ShopDetail_operationBar">
                        <div>
                            <div>
                                <div>
                                    <div><Icon type="customer" className="ShopDetail_operationBar_icon" /></div>
                                    <div>客服</div>
                                </div>
                                <div onClick={() => { this.props.history.push(`/shop_bus/${info.seller_id}`) }}>
                                    <div><Icon type="shop" className="ShopDetail_operationBar_icon" /></div>
                                    <div>店铺</div>
                                </div>
                            </div>
                            <div onClick={this.handleAddCart}>加入购物车</div>
                            <div onClick={this.handleGoPay}>立即购买</div>
                        </div>
                    </div>
                </div>
                <Modal
                    popup={true}
                    // closable={true}
                    visible={selectOptions}
                    onClose={this.onClose('selectOptions')}
                    animationType="slide-up"
                >
                    <div style={{ textAlign: 'center', lineHeight: '2rem' }}>商品参数</div>
                    <Gird style={{ height: '15.6rem', overflow: 'auto' }}>
                        {
                            info.parameter && info.parameter.map((item: any, i: number) => {
                                return (
                                    <Gird.Item className="t_z" title={item.name} value={item.value} key={i} />
                                )
                            })
                        }
                    </Gird>
                    <Button style={{ borderRadius: 0, width: '100%', border: 0, background: 'rgb(250, 0, 0)', color: '#fff' }} onClick={this.onClose('selectOptions')}>确定</Button>
                </Modal>
                <Modal
                    popup={true}
                    // closable={true}
                    visible={selectSpecifications}
                    onClose={this.onClose('selectSpecifications')}
                    animationType="slide-up"
                >
                    <div className="ShopDetail_specification">
                        <div className="ShopDetail_specification_goodsInfo">
                            <div>
                                <Image className="ShopDetail_specification_goodsImg" src={info.pic} />
                            </div>
                            <div>
                                <div>
                                    <span>￥</span>
                                    <span className="DINPro">{info.price}+{info.price_q}</span>
                                    <span>恒豆</span>
                                </div>
                                <p>商品编号：5089237</p>
                            </div>
                            <div>
                                <Icon
                                    type="close"
                                    className="ShopDetail_specification_closeIcon"
                                    onClick={() => { this.setState({ selectSpecifications: false }) }}
                                />
                            </div>
                        </div>
                        <div className="ShopDetail_specification_content">
                            {
                                spec.map((item: any, i: number) => {
                                    return (
                                        <div className="ShopDetail_specification_item" key={i}>
                                            <div className="ShopDetail_specification_itemTitle">{item.key}</div>
                                            <div className="ShopDetail_specification_selectWrap">
                                                {
                                                    isArray(item.value) && item.value.map((list: any, k: number) => (
                                                        <span onClick={this.handleSelectSpec.bind(this, i, k)} className={list.active ? 'ShopDetail_specification_active' : 'ShopDetail_specification_default'} key={k}>{list.label}</span>
                                                    ))
                                                }

                                                {/* <span className="ShopDetail_specification_default">深灰色</span> */}
                                            </div>
                                        </div>
                                    )
                                })
                            }

                            {/* <div className="ShopDetail_specification_item">
                                <div className="ShopDetail_specification_itemTitle">版本</div>
                                <div className="ShopDetail_specification_selectWrap">
                                    <span className=" ShopDetail_specification_default ShopDetail_specification_active">公开版</span>
                                    <span className="ShopDetail_specification_default ShopDetail_specification_active">原厂延保版</span>
                                    <span className="ShopDetail_specification_default ShopDetail_specification_active">无线充套装</span>
                                    <span className="ShopDetail_specification_default ShopDetail_specification_active">蓝牙耳机套装</span>
                                    <span className="ShopDetail_specification_default">手机膜套装</span>
                                </div>
                            </div>
                            <div className="ShopDetail_specification_item">
                                <div className="ShopDetail_specification_itemTitle">颜色</div>
                                <div className="ShopDetail_specification_selectWrap">
                                    <span className="ShopDetail_specification_active">64G</span>
                                    <span className="ShopDetail_specification_default">254G</span>
                                </div>
                            </div> */}
                            <div className="ShopDetail_specification_selectNum">
                                <div className="ShopDetail_specification_itemTitle">数量</div>
                                <InputNumber className="ShopDetail_specification_googsNum" min={1} max={info.number || 0} onChange={this.reduceGoodsNum} value={buyGoodsNum} />
                                {/* <div className="ShopDetail_specification_googsNum">
                                    <div onClick={this.reduceGoodsNum}>-</div>
                                    <div>{this.state.buyGoodsNum}</div>
                                    <div onClick={this.addGoodsNum}>+</div>
                                </div> */}
                            </div>
                        </div>
                        <div className="ShopDetail_specification_addGoods flex">
                            {this.jiarugouwuche && <Button className="gouwuche flex_1" onClick={this.handleAddCart} disabled={(info.spec && info.number) ? false : true}>加入购物车</Button>}
                            {this.lijigoumai && <Button className="liji flex_1" onClick={this.handleGoPay} disabled={(info.spec && info.number) ? false : true}>立即购买</Button>}
                        </div>
                    </div>
                </Modal>
                <Modal
                    popup={true}
                    visible={addressVisible}
                    onClose={this.onClose('addressVisible')}
                    animationType="slide-up"
                >
                    <div className="ShopDetail_address_selectTitle">
                        <div>&nbsp;</div>
                        <div>配送至</div>
                        <div>
                            <Icon type="close" onClick={this.onClose('addressVisible')} />
                        </div>
                    </div>
                    <div className="ShopDetail_address_selectWrap">
                        {
                            addressData.map((item: any, i: number) => {
                                return (
                                    <div
                                        className="ShopDetail_address_selectItem"
                                        key={i}
                                        onClick={this.handleSelectAddress.bind(this, i)}
                                    >
                                        <div className="flex_justify">
                                            <Icon type="address" style={{ fontSize: '0.8rem' }} />
                                        </div>
                                        <div className="flex_1">{item.province}{item.city}{item.area}{item.address}</div>
                                        <div className="flex_justify">
                                            {(item.active) ? <Icon type="tick" /> : <Icon type="tick" style={{ color: '#fff' }} />}
                                        </div>
                                    </div>
                                )
                            })
                        }
                    </div>
                    <div className="ShopDetail_address_addShop">
                        加入购物车
                    </div>
                </Modal>
                {/* 分享modal */}
                <Modal
                    popup={true}
                    visible={this.state.shareVisible}
                    onClose={this.onClose('shareVisible')}
                    animationType="slide-up"
                >
                    <div className="ShopDetail_share_wrap">
                        {
                            shareItem.map((item: any, i: number) => {
                                return (
                                    <Button key={i} className="ShopDetail_share_btn" style={{ color: item.color }}>
                                        <Icon type={item.icon} />
                                        {item.text}
                                    </Button>
                                )
                            })
                        }
                    </div>
                </Modal>
            </div>
        )
    }

    // private node: any

    public componentWillMount() {
        window.addEventListener('scroll', this.handleScroll)
    }

    public componentWillUnmount() {
        window.removeEventListener('scroll', this.handleScroll)
    }

    public componentDidMount() {
        this.getData()
    }

    private getData() {
        const { SET_DETAIL_DATA, SET_DETAIL_SPEC, SET_DETAIL_ADDRESS, userInfo, match } = this.props
        post('goodsapi/goodsDetail', { id: match.params.id, userId: userInfo.id }).then((data: any) => {
            SET_DETAIL_DATA(data)
            post('goodsapi/goodsRecommend', {
                category_id: data.category_id,
                id: match.params.id
            }).then((val: any) => {
                this.setState({
                    goodsRecommends: val
                })
            })
        })
        post('goodsapi/goodsStock', { id: match.params.id }).then((data: any) => {
            // // 初始化数据
            const newSpec = data.map((item: any) => {
                item.value = item.value.map((i: any) => {
                    const val: any = {}
                    val.label = i
                    val.active = false
                    return val
                })
                return item
            })
            SET_DETAIL_SPEC(newSpec)
        })
        if (userInfo.id) {
            post('goodsapi/addFootprints', {
                id: match.params.id,
                userId: userInfo.id
            })
            post('usersapi/userAddress', {
                id: match.params.id,
                userId: userInfo.id
            }).then((data: any) => {
                let addr = ''
                const newAddr = data.map((i: any) => {
                    i.active = false
                    if (i.status === 1) {
                        i.active = true
                        addr = `${i.province}${i.city}${i.area}${i.address}`
                    }
                    return i
                })
                SET_DETAIL_ADDRESS(newAddr)
                this.setState({
                    selectAddressVal: addr
                })
            })
        }
        // const { params } = this.props.match
        // const { userInfo } = this.props

        // const data = await post('goodsapi/goodsDetail', {
        //     id: params.id,
        //     userId: userInfo.id
        // })
        // const spec = await post('goodsapi/goodsStock', {
        //     id: params.id
        // })

        // const address = await post('usersapi/userAddress', { userId: userInfo.id })
        // this.setState({
        //     info: data,
        //     spec: newSpec,
        //     addressData: newAdre,
        //     selectAddressVal: addr
        // })
    }

    private onClose = (key: any) => () => {
        this.setState({
            [key]: false,
        })
    }

    private showModal = (key: any) => (e?: any) => {
        e.preventDefault() // 修复 Android 上点击穿透
        this.jiarugouwuche = true
        this.lijigoumai = true
        this.setState({
            [key]: true,
        })
    }

    private handleSelectSpec(i: number, k: number) {
        const { spec, SET_DETAIL_SPEC, SET_DETAIL_DATA } = this.props
        const { params } = this.props.match
        const val: any = [...spec]
        val[i].value = val[i].value.map((e: any) => {
            e.active = false
            return e
        })
        val[i].value[k].active = !val[i].value[k].active
        let all = true
        let str = ''
        val.map((item: any) => {
            const status = item.value.some((info: any) => {
                if (info.active) {
                    str += `${item.key}:${info.label},`
                }
                return info.active
            })
            if (!status) {
                all = false
            }
        })
        if (all) {
            Toast.loading('加载中...', 0)
            post('goodsapi/goodsStockNumber', {
                goods_id: params.id,
                stock: str.substring(0, str.length - 1)
            })
                .then((data: any) => {
                    if (!data.number) {
                        Toast.hide()
                        Toast.info('抱歉没有库存了~~', 1)
                        const { info } = this.props
                        SET_DETAIL_DATA(assign(info, data))
                    } else {
                        const set = () => {
                            Toast.hide()
                            const { info } = this.props
                            SET_DETAIL_DATA(assign(info, data))
                        }
                        setTimeout(set, 300)
                    }
                })
                .catch(() => {
                    Toast.hide()
                    Toast.info('网络堵塞,请稍后重试', 1)
                })
        }
        SET_DETAIL_SPEC(val)
    }

    private handleMoreVisibleChange = () => {
        // console.log(123)
    }

    private onSelect = () => {
        // console.log(456)
    }

    private reduceGoodsNum = (val: any) => {
        this.setState({
            buyGoodsNum: val
        })
    }

    private handleClickTabs = (tab: any, index: number) => {
        if (index === 1) {
            document.body.scrollTop = 698
            document.documentElement.scrollTop = 698
        }
        if (index === 0) {
            document.body.scrollTop = 0
            document.documentElement.scrollTop = 0
        }
        if (index === 2) {
            const dom: any = ReactDOM.findDOMNode(this.flatNode)
            if (dom) {
                document.body.scrollTop = dom.offsetTop - 40
                document.documentElement.scrollTop = dom.offsetTop - 40
            }
        }
    }

    private handleScroll = (event: any) => {
        const scrollTop = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset
        const { topBarClass, tabPage } = this.state
        const dom: any = ReactDOM.findDOMNode(this.flatNode)
        if (scrollTop > 44) {
            if (topBarClass !== 'ShopDetail_topBar ShopDetail_topBar_active') {
                this.setState({
                    topBarClass: 'ShopDetail_topBar ShopDetail_topBar_active',
                })
            }

        } else {
            if (topBarClass !== 'ShopDetail_topBar') {
                this.setState({
                    topBarClass: 'ShopDetail_topBar',
                })
            }
        }
        if (scrollTop > dom.offsetTop - 80) {
            this.setState({
                tabPage: 2
            })
        } else if (scrollTop > 690) {
            if (tabPage !== 1) {
                this.setState({
                    tabPage: 1
                })
            }
        } else {
            if (tabPage !== 0) {
                this.setState({
                    tabPage: 0
                })
            }
        }
    }

    private handleSeller = (status: number) => {
        const { userInfo, history, SET_DETAIL_DATA } = this.props
        const { info } = this.props
        if (!userInfo.id) {
            history.push('/loginMode')
        }
        post('goodsapi/goodsCollect', {
            userId: userInfo.id,
            state: status,
            id: info.id
        }).then((data: any) => {
            const val = { ...info }
            if (status === 1) {
                val.is_goods_collect = 1
            } else {
                val.is_goods_collect = 0
            }
            SET_DETAIL_DATA(val)
        })
    }

    private handleGoPay = () => {
        const { buyGoodsNum, selectAddressObj } = this.state
        const { info, history, SET_USER_DEFAULT_ADDRESS } = this.props
        if (!info.goods_list_id) {
            this.setState({
                'selectSpecifications': true
            })
            this.lijigoumai = true
            this.jiarugouwuche = false
            return
        }
        SET_USER_DEFAULT_ADDRESS(selectAddressObj)
        history.push(`/fillOrder?id=${info.id}-${info.goods_list_id}&number=${buyGoodsNum}`)
    }
    private handleAddCart = () => {
        const { buyGoodsNum } = this.state
        const { info, userInfo, history } = this.props
        if (!info.goods_list_id) {
            this.setState({
                'selectSpecifications': true
            })
            this.jiarugouwuche = true
            this.lijigoumai = false
            return
        }
        if (!userInfo) {
            history.push('/loginMode')
        }
        post('cartapi/cartAdd', { listId: info.goods_list_id, number: buyGoodsNum, userId: userInfo.id })
            .then((data: any) => {
                Toast.success('加入购物车成功', 2, () => {
                    this.setState({
                        selectSpecifications: false
                    })
                })
            })
            .catch((data: any) => {
                if (data.msg === '请先登录') {
                    history.push('/loginMode')
                } else {
                    Toast.info('网络堵塞,请稍后重试', 1)
                }
            })
    }

    private handleSelectAddress = (index: number) => {
        const { addressData } = this.props
        let addr = ''
        let selectAddressObj = {}
        const val = addressData.map((item: any, i: number) => {
            if (i === index) {
                item.active = true
                selectAddressObj = item
                addr = `${item.province}${item.city}${item.area}${item.address}`
            } else {
                item.active = false
            }
            return item
        })
        this.setState({
            addressData: val,
            selectAddressVal: addr,
            selectAddressObj,
            addressVisible: false
        })
    }
}